package com.summer.springboot.freemarker.controller;

import cn.hutool.core.date.DateUtil;
import com.summer.springboot.freemarker.vo.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("/template")
public class TemplateController {

    @GetMapping
    public String index(Model model) {
        model.addAttribute("userList", buildUserList());
        return "index";
    }


    private List<User> buildUserList() {
        List<User> list = new ArrayList<User>();
        for(int i = 0 ; i < 10; i++) {
            User user = new User();
            user.setUsername("username-" + i);
            user.setBorthday(DateUtil.formatDate(new Date()));
            user.setAddress("西安市-" + i);
            user.setId(i+"");
            list.add(user);
        }
        return list;
    }

}
